<template>
  <el-popover placement="top-start" :width="size" trigger="hover" :disabled="strLen <= len">
    <div>{{ str }}</div>
    <template v-if="strLen <= len" #reference>
      <span class="cut-string">{{ str }}</span>
    </template>
    <template v-else #reference>
      <span class="cut-string">{{ str.substr(0, len) + more }}</span>
    </template>
  </el-popover>
</template>

<script lang="ts" setup>
const props = defineProps({
  str: {
    type: [String,Number],
    default: ''
  },
  more: {
    type: String,
    default: '...'
  },
  len: {
    type: Number,
    default: 100
  },
  size: {
    type: Number,
    default: 300
  }
})

const strLen = computed(() => {
  return props.str && typeof props.str === 'string' ? props.str.length : 0
})
</script>

<style lang="scss" scoped>
span {
  user-select: text;
  -webkit-user-select: text;
}
</style>
